/**
 * Copyright 2010 Tristan Slominski
 *
 * Licensed under the MIT License (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.opensource.org/licenses/mit-license.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mindash.handlebars.client.wrappers.impl;

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.mindash.handlebars.client.wrappers.RootPanelWrapper;

/**
 * @author Tristan Slominski
 *
 */
public class RootPanelWrapperImpl implements RootPanelWrapper {

  /* variables */
  private Widget pageView;

  @Override
  public void addPage(Widget pageView) {
    setPageView(pageView);
    get().add((Widget) getPageView());
  }

  @Override
  public void clearPage() {
    if (getPageView() != null) {
      get().remove(getPageView());
    }
  }

  @Override
  public void detachNow(Widget widget) {
    com.google.gwt.user.client.ui.RootPanel.detachNow(widget);
  }

  @Override
  public void detachOnWindowClose(Widget widget) {
    com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(widget);
  }

  @Override
  public void ensureDebugId(Element elem, String id) {
    com.google.gwt.user.client.ui.RootPanel.ensureDebugId(elem, id);
  }

  @Override
  public com.google.gwt.user.client.ui.RootPanel get() {
    return com.google.gwt.user.client.ui.RootPanel.get();
  }

  @Override
  public com.google.gwt.user.client.ui.RootPanel get(String id) {
    return com.google.gwt.user.client.ui.RootPanel.get(id);
  }

  @Override
  public Element getBodyElement() {
    return com.google.gwt.user.client.ui.RootPanel.getBodyElement();
  }

  @Override
  public boolean isInDetachList(Widget widget) {
    return com.google.gwt.user.client.ui.RootPanel.isInDetachList(widget);
  }

  @Override
  public boolean isVisible(Element elem) {
    return com.google.gwt.user.client.ui.RootPanel.isVisible(elem);
  }

  @Override
  public void setVisible(Element elem, boolean visible) {
    com.google.gwt.user.client.ui.RootPanel.setVisible(elem, visible);
  }

  /* getters and setters */

  public void setPageView(Widget pageView) {
    this.pageView = pageView;
  }

  public Widget getPageView() {
    return pageView;
  }
}
